#ifndef ERRORS_H_
#define ERRORS_H_

#include <string>



/**
 * This namespace is used to define and reference error codes to pass
 * between methods.
 * This is mainly to improve readability (provided the error codes have
 * 'speaking' names) and to have a central place to define error codes.
 * 
 * Having all error codes in a central file does help avoiding multiple
 * definitions of meanings for one value. Keeps your applicaation con-
 * sistent. ;)
 * 
 * NOTE: The file is named '.hpp' to indicate that there is implementation code present
 **/
namespace errorCodes{

	/**
	 * Using an enum for the error codes has the advantage that all error
	 * codes will definitely have different values (which you actually don't
	 * have to care about anymore). Furthermore (and more important), they can
	 * be passed by their NAME, not their value, and methods returning an error
	 * (and only an error code) can be declared as such, e.g.
	 * 
	 * errorCodes::errorCode MyClass::myMethod(){
	 *     //...
	 *     return errorCodes::SUCCESS;
	 * }
	 * 
	 * By placing 'using namespace errorCodes;' at the top of you file you can
	 * actually skip the 'errorCodes::' parts, but I prefer if you can instantly
	 * see where those structs and constants are defined. Remember, somebody might
	 * have to read your code (or, worse, you'll have to do it yourself, half a 
	 * year later).
	 **/
	 enum errorCode{
	
		SUCCESS = 0,
		FAILURE,
		ERROR_ON_INIT
	
	};
	
	/**
	 * Obtain a descriptive string for an error code (e.g. for output reasons)
	 **/
	static std::string getCodeString(errorCode code){
		
		/* I usually disklike one-liner case statements, but it improves readability
		 * (and 'copyability') here. */
		switch(code){
			case SUCCESS: return "Success";
			case FAILURE: return "General failure";
			case ERROR_ON_INIT: return "Error during initilization";
			
			default: return "Unknown error code. This should not happen and most likely means that"
					"the developer was too lazy to keep the records.";
		}
	}

}





#endif /*ERRORS_H_*/
